package comunity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class UserInfo extends User {
	private String psw;
	//private String address;
	//private int port;
	private boolean newUser;

	private Socket socket;
	//private PrintWriter printWriter;
	//private BufferedReader bufferedReader;
	
	public UserInfo(Status status, String username,  String psw, /*String address, int port,*/ double lat, double lon) {
		super(status, username, lat, lon);
		this.psw = psw;
		//this.address = address;
		//this.port = port;
		this.newUser = false;
	}
	
	public void setSocket(Socket socket/*, PrintWriter printWriter, BufferedReader bufferedReader*/) throws IOException {
		this.socket = socket;
		//this.printWriter = printWriter;
		//this.bufferedReader = bufferedReader;
	}
	
	public void closeSocket() throws IOException{
		
		//this.socket.getInputStream().close();
		//this.socket.getOutputStream().close();
		this.socket.close();
		this.socket = null;
	}
	
	public boolean isSocketClose(){
		return this.socket.isClosed();
	}
	
	public boolean existSocket(){
		return this.socket != null;
	}
	
	public PrintWriter getPrintWriter(){
		PrintWriter pw = null;
		try {
			pw = new PrintWriter(socket.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return pw;
		//return this.printWriter;
	}
	
	public BufferedReader getBufferedReader(){
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return br;
		//return this.bufferedReader;
	}
	
	public boolean isNewUser() {
		return newUser;
	}
	
	public void setNewUser(boolean newUser) {
		this.newUser = newUser;
	}
	
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}
	
	String getPsw() {
		return psw;
	}
	/*
	public int getPort() {
		return port;
	}
	
	String getAddress() {
		return address;
	}
	
	void setPort(int port) {
		this.port = port;
	}
	
	void setAddress(String address) {
		this.address = address;
	}*/
}
